﻿@model List<ZX.HIS.Model.DrugWareHouse>

@{
    ViewBag.Title = "DrugWareHouseshow";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}
<script src="~/Content/BootstrapSouce/js/Common.js"></script>
<div id="urHere">DouPHP 管理中心<b>&gt;</b><strong>药品类型名</strong> </div>

<div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
    <h3>入库日志</h3>
    <div class="filter">
        <label for="drug-type">上传时间</label>
        <input type="date" class=" inpMain" id="PostDate" placeholder="" />至
        <input type="date" class=" inpMain" id="PostDate1" placeholder="" />
        <label for="drug-type">供应商</label>
        <select id="ProductId">
            <option value="0">请选择</option>

        </select>
        <script>
            $(function () {
                $.ajax({
                    type: "POST",
                    url: "/DrugWareHouse/Productlist",
                    success: function (data) {
                        var SeArray = new Array();
                        SeArray.push("<option value=\"0\">请选择</option>")
                        for (var i = 0; i < data.length; i++) {
                            SeArray.push("")
                            SeArray.push(" <option value=\"")
                            SeArray.push(data[i].ProductId)
                            SeArray.push("\">")
                            SeArray.push(data[i].ProductName)
                            SeArray.push("</option>")
                        };
                        $("#ProductId").html(SeArray.join(""))
                    }
                })
            })
        </script>
        <button type="button" class="btnGray" onclick="PageJump(1)">
            <span class="glyphicon glyphicon-search">查询</span>
        </button>
    </div>
    <table width="100%" class="table table-bordered  tableBasic order-list table-list">
        <thead>
            <tr>
                <th style="text-align:center">入库日期</th>
                <th style="text-align:center">药品名称</th>
                <th style="text-align:center">规格</th>
                <th style="text-align:center">生产厂家</th>
                <th style="text-align:center">批号</th>
                <th style="text-align:center">进货价</th>
                <th style="text-align:center">处方价</th>
                <th style="text-align:center">批次库存</th>
                <th style="text-align:center">有效期</th>
                <th style="text-align:center">操作</th>
            </tr>
        </thead>
        <tbody id="tbodyShow"></tbody>
    </table>
    <div class="divPage"></div>
</div>
<script>
        $(function () {
            //页面初次加载，调用AJAX，PageIndex 为1
            PageJump(1);
        })
        //分页数据加载方法
        function PageJump(PageIndex) {
            var ProductId = $("#ProductId").val();
            var PostDate = $("#PostDate").val();
            var PostDate1 = $("#PostDate1").val();
            $.ajax({
                type: "POST",
                url: "/DrugWareHouse/show",
                data: {
                    ProductId: ProductId,
                    PostDate: PostDate,
                    PostDate1: PostDate1,
                    PageIndex: PageIndex
                },
                success: function (data) {
                    var TrDemo = new Array();
                    var divDemo = new Array();
                    for (var i = 0; i < data.PageList.length; i++) {

                        TrDemo.push(" <tr>")
                        TrDemo.push("<td style=\"text-align:center\">");
                        //TrDemo.push(data.PageList[i].DrugNowDate);
                        TrDemo.push(ChangeDateFormat(data.PageList[i].DrugNowDate));
                        TrDemo.push("</td><td style=\"text-align:center\">");
                        TrDemo.push(data.PageList[i].DrugWareName);
                        TrDemo.push("</td><td style=\"text-align:center\">")
                        TrDemo.push(data.PageList[i].DrugWarePackSpece);
                        TrDemo.push("</td><td style=\"text-align:center\">")
                        TrDemo.push(data.PageList[i].ProductName);
                        TrDemo.push("</td> <td style=\"text-align:center\">")
                        TrDemo.push(data.PageList[i].DrugWareBatchNo);
                        TrDemo.push("</td><td style=\"text-align:center\">")
                        TrDemo.push(data.PageList[i].DrugPurchasePrice);
                        TrDemo.push("</td> <td style=\"text-align:center\">")
                        TrDemo.push(data.PageList[i].DrugWarePresPrice);
                        TrDemo.push("</td><td style=\"text-align:center\">")
                        TrDemo.push(data.PageList[i].DrugWareNumber);
                        TrDemo.push("</td><td style=\"text-align:center\">")
                        //TrDemo.push(data.PageList[i].DrugWareTime)
                        TrDemo.push(ChangeDateFormat(data.PageList[i].DrugWareTime));
                        TrDemo.push("</td>")
                        TrDemo.push("<td style=\"text-align:center\"><a href=\"/DrugWareHouse/UptDrugWareHouse?id=")
                        TrDemo.push(data.PageList[i].DrugWareId);
                        TrDemo.push("\"> 编辑</a></td>")
                        TrDemo.push("</tr>")

                    }
                    $("#tbodyShow").html(TrDemo.join(""));

                    //调用分页索引条
                    PageDemoSuccess(divDemo, data);
                    $(".divPage").html(divDemo.join(""));
                }
            })
        }
        //分页索引条加载方法
        function PageDemoSuccess(divDemo, data) {
            divDemo.push("<nav>")
            divDemo.push("<ul class=\"pagination \">")
            divDemo.push("<li>")
            divDemo.push(" <span>每页");
            divDemo.push("<input type=\"number\" class=\"inpMain\"  min=\"1\" style=\"width:40px;height:5px\" id=\"PageSize\" value=\"")
            divDemo.push(data.PageSize);
            divDemo.push("\" placeholder=\"\" />");
            divDemo.push(" 条</span></li>")
            divDemo.push("<li><span>共" + data.PageCount + "页，第" + data.PageIndex + "页，共" + data.PageNum + "条</span></li>")
            divDemo.push("<li><span onclick=\"PageJump(1)\" aria-label=\"Previous\"><span aria-hidden=\"true\">首页</span></span></li>")
            if (data.PageIndex <= 1) {
                divDemo.push("<li class=\"disabled\"><span onclick=\"PageJump(1)\">上一页</span></li>")
            }
            else {
                divDemo.push("<li><span onclick=\"PageJump(" + (data.PageIndex - 1) + ")\">上一页</span></li>")
            }
            for (var i = 0; i < data.PageCount; i++) {
                if (data.PageCount > 8) {
                    if (data.PageIndex == 1) {
                        if (i <= 3) {
                            if (i == 3) {
                                LiNoPush(divDemo);
                            } else {
                                LiJumpPush(data.PageIndex, i, divDemo)
                            }
                        } else {
                            break;
                        }
                    }
                    else if (data.PageIndex == data.PageCount) {

                        if (i >= (data.PageCount - 4)) {
                            if (i == data.PageCount - 4) {
                                LiNoPush(divDemo);
                            } else {
                                LiJumpPush(data.PageIndex, i, divDemo)
                            }
                        }
                        else {
                            continue;
                        }
                    } else {
                        if ((data.PageIndex - 3) <= i && i <= (data.PageIndex + 1)) {
                            if (data.PageIndex - 3 == i) {
                                LiNoPush(divDemo);
                            } else if (data.PageIndex + 1 == i) {
                                LiNoPush(divDemo);
                            } else {
                                LiJumpPush(data.PageIndex, i, divDemo)
                            }
                        } else {
                            continue;
                        }
                    }
                } else {
                    LiJumpPush(data.PageIndex, i, divDemo)
                }
            }
            if (data.PageIndex == data.PageCount) {
                divDemo.push("<li class=\"disabled\"><span onclick=\"PageJump(" + data.PageCount + ")\">下一页</span></li>")
            }
            else {
                divDemo.push("<li><span onclick=\"PageJump(" + (data.PageIndex + 1) + ")\">下一页</span></li>")
            }
            divDemo.push(" <li><span onclick=\"PageJump(" + data.PageCount + ")\" aria-label=\"Next\"><span aria-hidden=\"true\">尾页</span></span></li>")
            divDemo.push("</ul>")
            divDemo.push("</nav>")
        }
        //分页链接跳转方法
        function LiJumpPush(PageIndex, Num, Demo) {
            Demo.push("<li ")
            if (PageIndex == (Num + 1)) {
                Demo.push(" class=\"active\"")
            }
            Demo.push("><span onclick=\"PageJump(" + (Num + 1) + ")\">" + (Num + 1) + "</span></li>")
        }
        //省略号加载方法
        function LiNoPush(Demo) {
            Demo.push("<li><span>...</span></li>")
        }

</script>
